// pages/user/myOrderDeatil/myOrderDeatil.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tit: '',
    proImgArr: [0, 1, 2, 3],
    oInfo: {},//订单详情
    imgURL: app.globalData.imgURL,//图片总路径
    entrance: '0',
    showReleaseBtn:'0',
    buyId:'',
    productShow:'',
    toReleaseType:'',
    btnContext:'发布信息',
  },

  toRelease:function(e){
  var that = this;
  if(that.data.toReleaseType=="buyer"){
    wx.navigateTo({
      url: '../../buys/releaseInfo/releaseInfo?buyId=' + that.data.buyId,
    })
    
  }else{
    wx.navigateTo({
      url: '../../sells/sellsReleaseInfo/sellsReleaseInfo?buyId=' + that.data.buyId,
    })
  }
  
},

  imgClick: function (e) {
    var that = this;
    console.log(e);
    console.log(e.currentTarget.id);
    var imgArr = that.data.oInfo.picture_path;
    var nImgArr = new Array();
    for (var i = 0; i < imgArr.length; i++) {
      nImgArr[i] = that.data.imgURL + imgArr[i].replace('_thum', '');
    }
    console.log(nImgArr);
    wx.previewImage({
      current: nImgArr[e.currentTarget.id],
      urls: nImgArr,
    })
  },

  requestData: function (value, openid, type) {
    var that = this;

    app.post('orders/queryMyOrderDetail', { id: value, openId: openid, type: type }).then((res) => {
      console.log('success');
      console.log(res);
      if (res.code == 0) {
        var oInfo = res.resultData;
        if (oInfo.picture_path){
          oInfo.picture_path = oInfo.picture_path.split(',');
        }
        that.setData({
          oInfo: oInfo,
        })
      } else {
        wx.showModal({
          title: '温馨提示',
          content: res.msg,
          showCancel: false,
        })
      }
    }).catch((errMsg) => {
      console.log('fail');
      console.log(errMsg + '失败');
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("初始化页面加载:",options);
    var that = this;
    if(options.toReleaseType=="buyer"){
      that.setData({
        btnContext:'修改',
        toReleaseType:options.toReleaseType,
      })
    }

    if (options.entrance){
      that.setData({
        entrance: options.entrance
      })
    }
    if (options.showReleaseBtn){
      that.setData({
        showReleaseBtn: options.showReleaseBtn,
        buyId:options.id,
      })
    }
    if (options.productShow){
      that.setData({
        productShow: options.productShow,
      })
    }
    that.requestData(options.id, options.openId, options.type);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})